home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python151_Src.lha / Python1.5_Source / Amiga / fmod.c < prev    next >
C/C++ Source or Header  |  1996-12-19  |  692b  |  33 lines

  1.  
  2. /* Portable fmod(x, y) implementation for systems that don't have it */
  3.  
  4. /* This version adapted to Amiga FFP/IEEE roundoff errors */
  5.  
  6. #include "config.h"
  7. #include "mymath.h"
  8. #include <errno.h>
  9.  
  10.  
  11. /* Only use this function for FFP or IEEE math */
  12.  
  13. #if defined(_FFP) || (defined(_IEEE) && !defined(_M68881))
  14.  
  15. double fmod(double x, double y)
  16. {
  17.         double f;
  18.  
  19.         if (y == 0.0) {
  20.                 errno = EDOM;
  21.                 return 0.0;
  22.         }
  23.  
  24.         /* return f such that x = i*y + f for some integer i
  25.            such that |f| < |y| and f has the same sign as x */
  26.  
  27.         f = x-y*floor(x/y);
  28.                 if((f!=0.0) && ((x<0.0)!=(y<0.0))) f-=y;
  29.         return f;
  30. }
  31.  
  32. #endif
  33.